package ru.rchervot.sanasar.client.model;

import java.util.Date;

import com.google.gwt.user.client.rpc.IsSerializable;


public class SearchResultsItemCandidates extends AbstractSearchResultsItem implements IsSerializable {

    private String categories;
    private String languages;
    private String emplTitle;
    private String emplCompany;
    private Date contactDate;
    private String contactType;
    private String contactResult;
    private String contactNote;
    private String contactOrder;
    private String contactCompany;
    private String contactComp;
    private Date contactDatetime;
    private String contactPositionTitle;
    private String contactCreatorName;
    private String candName;
    private boolean deleted;
    private String updaterName;
    private String regionName;
    private Date updated;
    private String contactsEmail;
    private String contactsPhones;
    private Integer compensation;
    private String compensationView;
    private String compensationCurrency;
    private float currencyRate;
    private float currencyRateRUR;
    private Integer regionId;
    private Integer contactCreatorId;
    private Integer updaterId;
    private Integer fileId;
    private Integer emplBranchId;
    private Integer emplPositionId;
    private Integer emplOrderId;
    private Integer contactId;
    private int contactOrderId;
    private Integer contactBranchId;
    private Integer contactResultId;
    private Integer contactPositionId;
    private boolean plus;
    private boolean contactPerson;
    private String homeCity;
    private Integer candRating;
    
    /** Creates a new instance of CandidateView */
    public SearchResultsItemCandidates() {
    	super();
    }


    /**
     * Gets the categories of this CandidateView.
     * 
     */
    public String getCategories() {
        return this.categories;
    }

    /**
     * Sets the categories of this CandidateView to the specified value.
     * 
     */
    public void setCategories(String categories) {
        this.categories = categories;
    }

    /**
     * Gets the languages of this CandidateView.
     * 
     */
    public String getLanguages() {
        return this.languages;
    }

    /**
     * Sets the languages of this CandidateView to the specified value.
     * 
     */
    public void setLanguages(String languages) {
        this.languages = languages;
    }

    /**
     * Gets the emplTitle of this CandidateView.
     * 
     */
    public String getEmplTitle() {
        return this.emplTitle;
    }

    /**
     * Sets the emplTitle of this CandidateView to the specified value.
     * 
     */
    public void setEmplTitle(String emplTitle) {
        this.emplTitle = emplTitle;
    }

    /**
     * Gets the emplCompany of this CandidateView.
     * 
     */
    public String getEmplCompany() {
        return this.emplCompany;
    }

    /**
     * Sets the emplCompany of this CandidateView to the specified value.
     * 
     */
    public void setEmplCompany(String emplCompany) {
        this.emplCompany = emplCompany;
    }

    /**
     * Gets the contactDate of this CandidateView.
     * 
     */
    public Date getContactDate() {
        return this.contactDate;
    }

    /**
     * Sets the contactDate of this CandidateView to the specified value.
     * 
     */
    public void setContactDate(Date contactDate) {
        this.contactDate = contactDate;
    }

    /**
     * Gets the contactType of this CandidateView.
     * 
     */
    public String getContactType() {
        return this.contactType;
    }

    /**
     * Sets the contactType of this CandidateView to the specified value.
     * 
     */
    public void setContactType(String contactType) {
        this.contactType = contactType;
    }

    /**
     * Gets the contactResult of this CandidateView.
     * 
     */
    public String getContactResult() {
        return this.contactResult;
    }

    /**
     * Sets the contactResult of this CandidateView to the specified value.
     * 
     */
    public void setContactResult(String contactResult) {
        this.contactResult = contactResult;
    }

    /**
     * Gets the contactNote of this CandidateView.
     * 
     */
    public String getContactNote() {
        return this.contactNote;
    }

    /**
     * Sets the contactNote of this CandidateView to the specified value.
     * 
     */
    public void setContactNote(String contactNote) {
        this.contactNote = contactNote;
    }

    /**
     * Gets the contactOrder of this CandidateView.
     * 
     */
    public String getContactOrder() {
        return this.contactOrder;
    }

    /**
     * Sets the contactOrder of this CandidateView to the specified value.
     * 
     */
    public void setContactOrder(String contactOrder) {
        this.contactOrder = contactOrder;
    }

    /**
     * Gets the contactCompany of this CandidateView.
     * 
     */
    public String getContactCompany() {
        return this.contactCompany;
    }

    /**
     * Sets the contactCompany of this CandidateView to the specified value.
     * 
     */
    public void setContactCompany(String contactCompany) {
        this.contactCompany = contactCompany;
    }

    /**
     * Gets the contactComp of this CandidateView.
     * 
     */
    public String getContactComp() {
        return this.contactComp;
    }

    /**
     * Sets the contactComp of this CandidateView to the specified value.
     * 
     */
    public void setContactComp(String contactComp) {
        this.contactComp = contactComp;
    }

    /**
     * Gets the contactDatetime of this CandidateView.
     * 
     */
    public Date getContactDatetime() {
        return this.contactDatetime;
    }

    /**
     * Sets the contactDatetime of this CandidateView to the specified value.
     * 
     */
    public void setContactDatetime(Date contactDatetime) {
        this.contactDatetime = contactDatetime;
    }

    /**
     * Gets the contactPositionTitle of this CandidateView.
     * 
     */
    public String getContactPositionTitle() {
        return this.contactPositionTitle;
    }

    /**
     * Sets the contactPositionTitle of this CandidateView to the specified value.
     * 
     */
    public void setContactPositionTitle(String contactPositionTitle) {
        this.contactPositionTitle = contactPositionTitle;
    }

    /**
     * Gets the contactCreatorName of this CandidateView.
     * 
     */
    public String getContactCreatorName() {
        return this.contactCreatorName;
    }

    /**
     * Sets the contactCreatorName of this CandidateView to the specified value.
     * 
     */
    public void setContactCreatorName(String contactCreatorName) {
        this.contactCreatorName = contactCreatorName;
    }

    /**
     * Gets the candName of this CandidateView.
     * 
     */
    public String getCandName() {
        return this.candName;
    }

    /**
     * Sets the candName of this CandidateView to the specified value.
     * 
     */
    public void setCandName(String candName) {
        this.candName = candName;
    }

    /**
     * Gets the deleted of this CandidateView.
     * 
     */
    public boolean getDeleted() {
        return this.deleted;
    }

    /**
     * Sets the deleted of this CandidateView to the specified value.
     * 
     */
    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    /**
     * Gets the updaterName of this CandidateView.
     * 
     */
    public String getUpdaterName() {
        return this.updaterName;
    }

    /**
     * Sets the updaterName of this CandidateView to the specified value.
     * 
     */
    public void setUpdaterName(String updaterName) {
        this.updaterName = updaterName;
    }

    /**
     * Gets the regionName of this CandidateView.
     * 
     */
    public String getRegionName() {
        return this.regionName;
    }

    /**
     * Sets the regionName of this CandidateView to the specified value.
     * 
     */
    public void setRegionName(String regionName) {
        this.regionName = regionName;
    }

    /**
     * Gets the updated of this CandidateView.
     * 
     */
    public Date getUpdated() {
        return this.updated;
    }

    /**
     * Sets the updated of this CandidateView to the specified value.
     * 
     */
    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    /**
     * Gets the contactsInfo of this CandidateView.
     * 
     */
    public String getContactsInfo() {
        return (contactsPhones == null ? "" : contactsPhones) + 
                (contactsEmail == null ? "" : (" " + contactsEmail));
    }


    /**
     * Gets the regionId of this CandidateView.
     * 
     */
    public Integer getRegionId() {
        return this.regionId;
    }

    /**
     * Sets the regionId of this CandidateView to the specified value.
     * 
     */
    public void setRegionId(Integer regionId) {
        this.regionId = regionId;
    }

    /**
     * Gets the contactCreatorId of this CandidateView.
     * 
     */
    public Integer getContactCreatorId() {
        return this.contactCreatorId;
    }

    /**
     * Sets the contactCreatorId of this CandidateView to the specified value.
     * 
     */
    public void setContactCreatorId(Integer contactCreatorId) {
        this.contactCreatorId = contactCreatorId;
    }

    /**
     * Gets the updaterId of this CandidateView.
     * 
     */
    public Integer getUpdaterId() {
        return this.updaterId;
    }

    /**
     * Sets the updaterId of this CandidateView to the specified value.
     * 
     */
    public void setUpdaterId(Integer updaterId) {
        this.updaterId = updaterId;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs 
     * that representation based on the id fields.
     * 
     */
    
    public String toString() {
        return "SearchResultsItemCandidate[itemID=" + getItemID() + "]";
    }
    
    

    public String getCandAge() {
        return "";
    }
    
    public Integer getFileId() {
        return fileId;
    }

    public void setFileId(Integer fileId) {
        this.fileId = fileId;
    }

    
    private Date viewed;

    public Date getViewed() {
        return viewed;
    }

    public void setViewed(Date viewed) {
        this.viewed = viewed;
    }
    
    public boolean isWasViewed() {
        if (viewed == null) {
            return false;
        } else {
            return true;
        }
    }
    
    public Integer getEmplOrderId() {
        return emplOrderId;
    }

    public void setEmplOrderId(Integer emplOrderId) {
        this.emplOrderId = emplOrderId;
    }

    public Integer getContactId() {
        return contactId;
    }

    public void setContactId(Integer contactId) {
        this.contactId = contactId;
    }

    public int getContactOrderId() {
        return contactOrderId;
    }

    public void setContactOrderId(int contactOrderId) {
        this.contactOrderId = contactOrderId;
    }

    public Integer getContactBranchId() {
        return contactBranchId;
    }

    public void setContactBranchId(Integer contactBranchId) {
        this.contactBranchId = contactBranchId;
    }

    public Integer getContactResultId() {
        return contactResultId;
    }

    public void setContactResultId(Integer contactResultId) {
        this.contactResultId = contactResultId;
    }

    public Integer getContactPositionId() {
        return contactPositionId;
    }

    public void setContactPositionId(Integer contactPositionId) {
        this.contactPositionId = contactPositionId;
    }
    
    public String getAgeView() {
      if (birthYear == null || birthYear.intValue() == 0) return null;
      
      Date now = new Date();
      
      Date birth = null;

      try {
          if (birthMonth != null && birthDay != null && birthMonth >= 0 && birthDay > 0) {
              birth = new Date(birthYear, birthMonth, birthDay);
          } else {
              birth = new Date(birthYear, 0, 1);
          }
      } catch (Exception ex) {
          return "Error!!!";
      }
      
      int age = now.getYear() + 1900 - birthYear.intValue();
      
      if (birth.getMonth() >= now.getMonth() && birth.getDate() > now.getDate()) {
          age--;
      }
      
      String result = "" + age;
      
//      int r = age % 10;
      
      // add suffix
//      switch (r) {
//          case 1 : result += " год"; break;
//          case 2 :
//          case 3 :
//          case 4 : result += " года"; break;
//          case 5 :
//          case 6 :
//          case 7 :
//          case 8 :
//          case 9 : 
//          case 0 : result += " лет"; break;
//      }
      
      return result;
  }
    
    
    
    public boolean isFileAttached() {
        if (fileId != null && fileId > 0) {
            return true;
        } else {
            return false;
        }
    }
    
    public boolean isPlacement() {
        if (emplOrderId != null && emplOrderId > 0) {
            return true;
        } else {
            return false;
        }
    }
    
    public boolean isEmptyContact() {
        if (contactId != null && contactId > 0) {
            return false;
        } else {
            return true;
        }
    }
    
    public boolean isEmptyComment() {
        if (contactNote == null) {
            return true;
        } else {
            return false;
        }
    }
    
    public boolean getPlus() {
        return plus;
    }

    public void setPlus(boolean plus) {
        this.plus = plus;
    }

    public boolean getContactPerson() {
        return contactPerson;
    }

    public void setContactPerson(boolean contactPerson) {
        this.contactPerson = contactPerson;
    }
    
    public String getMark() {
        if (plus) {
            return "+";
        } else {
            return "";
        }
    }

    public String getHomeCity() {
        return homeCity;
    }

    public void setHomeCity(String homeCity) {
        this.homeCity = homeCity;
    }

    public String getContactsEmail() {
        return contactsEmail;
    }

    public void setContactsEmail(String contactsEmail) {
        this.contactsEmail = contactsEmail;
    }

    public String getContactsPhones() {
        return contactsPhones;
    }

    public void setContactsPhones(String contactsPhones) {
        this.contactsPhones = contactsPhones;
    }

    public String getCompensationViewUSD() {
        if (compensation == null || compensation.intValue() == 0) {
            return null;
        }
        
        String result = "$";
        
        if (compensationCurrency.equalsIgnoreCase("USD")) {
            result += compensation;
        } else if (compensationCurrency.equalsIgnoreCase("RUR")) {
            result += Math.round(compensation / (currencyRate * 50)) * 50 ;
        }
        
        return result;
    }

    

    public String getCompensationViewRUR() {
        if (compensation == null || compensation.intValue() == 0) {
            return null;
        }
        
        String result = "";
        
        if (compensationCurrency.equalsIgnoreCase("USD")) {
            result += Math.round((compensation * currencyRateRUR) / 1000) * 1000;
        } else if (compensationCurrency.equalsIgnoreCase("RUR")) {
            result += compensation;
        }
        
        result += "руб";
        
        return result;
    }

    static int moneyMod(int sum) {
        if (sum < 1000) {
            sum = (sum / 10) * 10;
        } else if (sum < 10000) {
            sum = (sum / 100) * 100;
        } else if (sum < 100000) {
            sum = (sum / 1000) * 1000;
        } else if (sum < 1000000) {
            sum = (sum / 10000) * 10000;
        } else if (sum < 10000000) {
            sum = (sum / 100000) * 100000;
        } else if (sum < 100000000) {
            sum = (sum / 1000000) * 1000000;
        } else if (sum < 1000000000) {
            sum = (sum / 10000000) * 10000000;
        } else {
            sum = (sum / 100000000) * 100000000;
        }
        
        return sum;
    }
    
    public String getCompensationView() {
    	return compensationView;
    }
    
//    public String getCompensationView() {
//        if (compensation == null || compensation.intValue() == 0) {
//            return null;
//        }
//        
//        String result = "";
//        
//        if (compensationPeriod == DomainConstants.COMPENSATION_PERIOD_YEAR) {
//            result += moneyMod((int)(compensation * DomainConstants.COMPENSATION_PERIOD_YEAR));
//        } else {
//            result += compensation;
//        }
//        
//        
//        if (compensationCurrency.equalsIgnoreCase("USD")) {
//            result = "$" + result;
//        } else if (compensationCurrency.equalsIgnoreCase("RUR")) {
//            result = "P" + result;
//        } else if (compensationCurrency.equalsIgnoreCase("EUR")) {
//            result = "\u20AC" + result;
//        }
//        
//        if (compensationType == DomainConstants.COMPENSATION_TYPE_GROSS) {
//            result += "g";
//        } else {
//            result += "n";
//        }
//        
//        return result;
//    }
    
    public Integer getCompensation() {
        return compensation;
    }

    public void setCompensation(Integer compensation) {
        this.compensation = compensation;
    }

    public String getCompensationCurrency() {
        return compensationCurrency;
    }

    public void setCompensationCurrency(String compensationCurrency) {
        this.compensationCurrency = compensationCurrency;
    }

    public float getCurrencyRate() {
        return currencyRate;
    }

    public void setCurrencyRate(float currencyRate) {
        this.currencyRate = currencyRate;
    }

    public float getCurrencyRateRUR() {
        return currencyRateRUR;
    }

    public void setCurrencyRateRUR(float currencyRateRUR) {
        this.currencyRateRUR = currencyRateRUR;
    }

    
    private String creatorName;

    public String getCreatorName() {
        return creatorName;
    }

    public void setCreatorName(String creatorName) {
        this.creatorName = creatorName;
    }
    
    
    
    private Date created;

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }
    
    
    private Integer creatorId;

    public Integer getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(Integer creatorId) {
        this.creatorId = creatorId;
    }
    
    
    private boolean client;

    public boolean getClient() {
        return client;
    }

    public void setClient(boolean client) {
        this.client = client;
    }
    
    
    
    private Date clientLastOrder;

    public Date getClientLastOrder() {
        return clientLastOrder;
    }

    public void setClientLastOrder(Date clientLastOrder) {
        this.clientLastOrder = clientLastOrder;
    }
    
    
    
    private Date emplStartDate;

    public Date getEmplStartDate() {
        return emplStartDate;
    }

    public void setEmplStartDate(Date emplStartDate) {
        this.emplStartDate = emplStartDate;
    }
    
    
    private Integer birthDay;
    
    
    private Integer birthMonth;
    
    
    private Integer birthYear;

    public Integer getBirthDay() {
        return birthDay;
    }

    public void setBirthDay(Integer birthDay) {
        this.birthDay = birthDay;
    }

    public Integer getBirthMonth() {
        return birthMonth;
    }

    public void setBirthMonth(Integer birthMonth) {
        this.birthMonth = birthMonth;
    }

    public void setBirthYear(Integer birthYear) {
        this.birthYear = birthYear;
    }

    public Integer getBirthYear() {
        return birthYear;
    }
    
    
    private String userLabels;

    public String getUserLabels() {
        return userLabels;
    }

    public void setUserLabels(String userLabels) {
        this.userLabels = userLabels;
    }
    
    public boolean isHasLabels() {
        if (userLabels == null || userLabels.length() == 0) {
            return false;
        } else {
            return true;
        }
    }

    public Integer getCandRating() {
        return candRating;
    }

    public void setCandRating(Integer candRating) {
        this.candRating = candRating;
    }
    
    
    private Integer status;

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
    
    
    private float compensationType;

    public float getCompensationType() {
        return compensationType;
    }

    public void setCompensationType(float compensationType) {
        this.compensationType = compensationType;
    }
    
    
    private float compensationPeriod;

    public float getCompensationPeriod() {
        return compensationPeriod;
    }

    public void setCompensationPeriod(float compensationPeriod) {
        this.compensationPeriod = compensationPeriod;
    }

    public Integer getEmplBranchId() {
        return emplBranchId;
    }

    public void setEmplBranchId(Integer emplBranchId) {
        this.emplBranchId = emplBranchId;
    }

    public Integer getEmplPositionId() {
        return emplPositionId;
    }

    public void setEmplPositionId(Integer emplPositionId) {
        this.emplPositionId = emplPositionId;
    }
    
    private Integer itemID;

	public Integer getItemID() {
		return itemID;
	}

	public void setItemID(Integer itemID) {
		this.itemID = itemID;
	}


	public void setCompensationView(String compensationView) {
		this.compensationView = compensationView;
	}

	
}
